package com.onedec.designer.service.impl;

import com.onedec.designer.entity.OnedecMaterial;
import com.onedec.designer.entity.OnedecMaterialExample;
import com.onedec.designer.mapper.OnedecMaterialMapper;
import com.onedec.designer.service.OnedecMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OnedecMaterialServiceImpl implements OnedecMaterialService {
    @Autowired
    private OnedecMaterialMapper onedecMaterialMapper;

    @Override
    public List<OnedecMaterial> selectAll() {
        return onedecMaterialMapper.selectByExample(null);
    }

    @Override
    public List<OnedecMaterial> selectByCategory(String Category) {
        OnedecMaterialExample onedecMaterialExample = new OnedecMaterialExample();
        OnedecMaterialExample.Criteria or = onedecMaterialExample.or();
        or.andMaterialCategoryEqualTo(Category);
        return onedecMaterialMapper.selectByExample(onedecMaterialExample);
    }

    @Override
    public List<OnedecMaterial> selectByName(String name) {
        OnedecMaterialExample onedecMaterialExample = new OnedecMaterialExample();
        OnedecMaterialExample.Criteria or = onedecMaterialExample.or();
        or.andMaterialNameEqualTo(name);
        return onedecMaterialMapper.selectByExample(onedecMaterialExample);
    }

    @Override
    public OnedecMaterial selectById(int id) {
        return onedecMaterialMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<OnedecMaterial> selectByNum(String num) {
        OnedecMaterialExample onedecMaterialExample = new OnedecMaterialExample();
        OnedecMaterialExample.Criteria or = onedecMaterialExample.or();
        or.andMaterialOperationNumEqualTo(num);
        return onedecMaterialMapper.selectByExample(onedecMaterialExample);
    }
}
